# ifndef __Tool_H_
# define __Tool_H_

	// Current cursor: permanent or 'wait' one.
extern HCURSOR g_hCursor;
	// Permanent cusor.
extern HCURSOR g_hPermanentCursor;

///////////////////////////////////////////

enum Tool_t {
	toolDrag      = 0,
	toolZoom      = 1,
	toolSelect    = 2,
	toolEditNodes = 3,
	toolCreate    = 4,
	toolTrim      = 5,
	toolTransform = 6,
	toolDummy     = 7,
	toolRouting   = 8,

	toolMax,
	toolDefault = toolDrag
};

class CTool {
  public:
	virtual bool Init () {return true;}
	virtual void Destroy () {}

	virtual void OnNewMap     () {}
	virtual void OnRemoveMap  () {}
	virtual void OnActivate   () {}
	virtual void OnDeactivate () {}

	virtual void OnLDown   (int _x, int _y, DWORD _dwKeys) {}
	virtual void OnLUp     (int _x, int _y, DWORD _dwKeys) {}
	virtual void OnLDblClk (int _x, int _y, DWORD _dwKeys) {OnLDown (_x, _y, _dwKeys);}
	virtual void OnRDown   (int _x, int _y, DWORD _dwKeys) {}
	virtual void OnRUp     (int _x, int _y, DWORD _dwKeys) {}
	virtual void OnMove    (int _x, int _y, DWORD _dwKeys) {}

	virtual void OnCtxMenu (int _x, int _y) {}
	virtual void OnEsc   () {}
	virtual void OnBack  () {}
	virtual void OnEnter () {}
	virtual bool OnCommand (WORD _wID) {return false;}
	virtual void OnSwitchSubTool () {}

	virtual void OnPaint (HDC _hDC, const RECT & _rect) {}

	//////////////////////////

	static CTool * GetCurrentTool () {return s_pTool;}
	static Tool_t GetCurrentToolId ();
	static void SetCurrentTool (Tool_t _Tool);

	static bool PendingDND () {return s_bDND;}
	static void SetPermanentCursor (HCURSOR _hcur);

	static bool _Init ();
	static void _Destroy ();
	static void _OnNewMap ();
	static void _OnRemoveMap ();
	static void _OnCtxMenu (int _x, int _y);
	static void _OnEsc   ();
	static void _OnBack  ();
	static void _OnEnter ();
	static void _OnMove    (int _x, int _y, DWORD _dwKeys);
	static void _OnLDown   (int _x, int _y, DWORD _dwKeys);
	static void _OnLUp     (int _x, int _y, DWORD _dwKeys);
	static void _OnLDblClk (int _x, int _y, DWORD _dwKeys);
	static void _OnRDown   (int _x, int _y, DWORD _dwKeys);
	static void _OnRUp     (int _x, int _y, DWORD _dwKeys);
	static void _OnPaint   (HDC _hDC, const RECT & _rect);
	static bool _OnCommand (WORD _wID);

  private:
	static CTool * s_pTool;

	// Data for unwanted drag suppression while short click.
	static size_t s_cXDrag, s_cYDrag;
	static int s_iXDragStart, s_iYDragStart;
	static DWORD s_dwTimeDragStart;
	static bool m_bSuppressDrag;

  protected:
	// Drag-and-drop mode flag.
	static bool s_bDND;
	// Drag-and-drop start position.
	static long s_lX_DND_Start, s_lY_DND_Start;
	// Drag-and-drop start time.
	static DWORD s_dwTime_DND_Start;
	// Drag-and-drop current position.
	static long s_lX_DND, s_lY_DND;

	void StartDND (long _lX, long _lY);
	void StopDND ();

  public:
	const Tool_t m_ToolId;

	static CTool * s_pFirst;
	CTool * m_pNext;
	static CTool * FindTool (Tool_t _ToolId);

	CTool (Tool_t _ToolId);
};


# define DECLARE_TOOL(_CTool) \
	static _CTool _CTool##_instance;


# endif // __Tool_H_